import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { Supplier } from 'src/supplier/entities/supplier.entity'; // 确保路径正确
import { ProductInfo } from 'src/product-info/entities/product-info.entity';

@Entity({ name: 'quote' }) // 指定表名
export class Quote {
  @PrimaryGeneratedColumn({ name: '_Identify' })
  id: number;

  @Column()
  productcode: string;

  @Column()
  productname: string;

  @Column({ type: 'float' })
  pricein: number;

  @Column({ type: 'int', name: 'supplier' })
  supplierid: number;

  @Column({ type: 'float' })
  profitpercent: number;

  @Column({ type: 'int' })
  includetax: boolean;

  @CreateDateColumn({ type: 'timestamp' })
  date: Date;

  @Column()
  size: string;

  @Column({ nullable: true })
  picture: string;

  @Column({ type: 'float' })
  whitepricein: number;

  @Column({ type: 'varchar' })
  productuniquecode: string;

  @ManyToOne(() => ProductInfo, (productinfo) => productinfo.quotes)
  @JoinColumn({
    name: 'productuniquecode',
    referencedColumnName: 'productuniquecode',
  }) // 确保外键列名正确
  productinfo: ProductInfo;

  @Column()
  quoteid: string;

  @Column({ type: 'int' })
  deleted: boolean;

  @ManyToOne(() => Supplier, (supplier) => supplier.quotes)
  @JoinColumn({ name: 'supplier' }) // 确保外键列名正确
  supplier: Supplier;
}
